﻿using CarEdge.Repository.Interface;
using CarEdge.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace CarEdge.Service.EFCore
{
    public class Base_EFCore<T> : I_Base_EFCore<T> where T : class, new()
    {

        private readonly I_Repository<T> _respository;
        public Base_EFCore(I_Repository<T> respository) {
            _respository = respository;
        }
        /// <summary>
        /// 新增单个实体
        /// </summary>
        /// <param name="entity"></param>
        public void Add(T entity)
        {
            _respository.Add(entity);
        }

        public void AddRange(IEnumerable<T> ie)
        {
            _respository.AddRange(ie);
        }

        public void Delete(T entity)
        {
           _respository.Delete(entity);
        }

        public void DeleteRange(IEnumerable<T> ie)
        {
            _respository.DeleteRange(ie);
        }

        public IQueryable<T> QueryAll(Expression<Func<T, bool>>? where = null)
        {
            return _respository.QueryAll(where);
        }

        public IQueryable<T> QueryAll<type>(bool isAsc, Expression<Func<T, type>> order, Expression<Func<T, bool>>? where = null)
        {
            return _respository.QueryAll<type>(isAsc, order, where);
        }

        public IQueryable<T> QueryAll<type>(out int total, int page, int limit, bool isAsc, Expression<Func<T, type>> order, Expression<Func<T, bool>>? where = null)
        {
            return _respository.QueryAll(out total, (page - 1) * limit, limit, isAsc, order, where);
        }

        public int SaveChanges()
        {
            return _respository.SaveChanges();
        }
        public Task<int> SaveChangesAsync()
        {
            return _respository.SaveChangesAsync();
        }

        public void Update(T entity)
        {
           _respository.Update(entity);
        }

        public void UpdateRange(IEnumerable<T> ie)
        {
            _respository.UpdateRange(ie);
        }
    }
}
